
*	************************************************************************
* 	File-Name: 	main.do
*	Log-file:	n/a
*	Date:  		1 August 2017
*	Author: 	Michael Aklin, Patrick Bayer, S.P. Harish, and Johannes Urpelainen
*	Data Used:  adoption_data.dta (through prep.do) / summer_survey.dta
*	Output		n/a
*	Purpose:   	replication file for results in main paper
*	************************************************************************

capture log close
clear all
set more off

*	************************************************************************
*	Load data
*	************************************************************************

* Run prep.do to set data up for analysis, create variables and correct labels
do "./prep.do"

*	************************************************************************


*	************************************************************************
* Table 1: Reported use of lighting for social and economic activities
*	************************************************************************

* Social activities
tab Q966_cooking if survey==1
tab Q965_family if survey==1
tab Q967_goingout if survey==1
tab Q964_friends if survey==1
tab Q912_kidsstudying if survey==1
tab Q9106_livestock if survey==1 
tab Q962_studying if survey==1
tab Q963_reading if survey==1 


* Economic activities
tab Q961_homebusiness if survey==1
tab Q9101_baking if survey==1
tab Q9105_manufacture if survey==1
tab Q9104_repairs if survey==1
tab Q9103_handicraft if survey==1
tab Q9102_decoration if survey==1

*	************************************************************************
*	Table 2: Use of lighting from summer survey
*	************************************************************************

clear all
use "./summer_survey.dta"
tab primary_use

*	************************************************************************
* Table 3: Reasons for non-adoption:
*	************************************************************************

* NB: Reload orignal data
capture log close
clear all
set more off
do "./prep.do"

tab MGPno


*	************************************************************************
*	Table 4: Reasond to discontinue service
*	************************************************************************

tab discont_reason

*	************************************************************************
*	Table 5: Summary statistics (full sample; all pre-treatment)
*	************************************************************************

eststo clear
eststo: estpost sum logexpenses logsavings debt risk business riskaverse trust_people_index trust_firms_index logpublic logprivate elec size age educ scheduled backward satisfaction expend if survey==1

/*
esttab using "./SummaryStats.tex"	///
	, ///
	cells("mean(fmt(2)) sd(fmt(2)) min(fmt(0)) max(fmt(0)) count(fmt(0))") ///
	substitute(m$ m\\$) collabels("Mean" "SD" "Min" "Max" "$ \#$") ///
	nonumber noobs label replace unstack
*/

*	************************************************************************
*	Table 6: Summary statistics for time-varying variables by survey
*	************************************************************************

sort survey
by survey: sum logexpenses logsavings debt business trust_people_index trust_firms_index logpublic logprivate elec satisfaction expend


*	************************************************************************
*	Table 7: Summary statistics (by adoption status and before/after adoption)
*	************************************************************************

* We need to exclude the 'riskaverse' variable as it's measured only once

*	Before/After
eststo clear
gen group_beforeafter_na = ""
replace group_beforeafter_na = "(a) Before Intervention" if adopted == 0 & survey == 1
replace group_beforeafter_na = "(b) After Intervention" if adopted == 0 & (survey == 2 | survey == 3)

*eststo clear
bysort group_beforeafter_na: eststo: estpost sum logexpenses logsavings debt risk business trust_people_index trust_firms_index logpublic logprivate elec size age educ scheduled backward satisfaction expend, listwise
/*
esttab using "./SummaryStatsByGroupBeforeAfterNonAdopter.tex"	///
	, ///
	cells("mean(fmt(2)) sd(fmt(2)) ") ///
	substitute(m$ m\\$) collabels("Mean" "SD" "Min" "Max" "$ \#$") ///
	nonumber noobs label replace unstack nodepvar
*/ 

gen group_beforeafter_adopt = ""
replace group_beforeafter_adopt = "(a) Before Intervention" if adopted == 1 & survey == 1
replace group_beforeafter_adopt = "(b) After Intervention" if adopted == 1 & (survey == 2 | survey == 3)

eststo clear
bysort group_beforeafter_adopt: eststo: estpost sum logexpenses logsavings debt risk business trust_people_index trust_firms_index logpublic logprivate elec size age educ scheduled backward satisfaction expend, listwise

/*
esttab using "./SummaryStatsByGroupBeforeAfterAdopter.tex"	///
	, ///
	cells("mean(fmt(2)) sd(fmt(2)) ") ///
	substitute(m$ m\\$) collabels("Mean" "SD" "Min" "Max" "$ \#$") ///
	nonumber noobs label replace unstack nodepvar
*/


*	************************************************************************
*	Table 8: Main results table (panel data)
*	************************************************************************

* Make sure that covariates are pre-treatment
tsset Q11_hhid survey
by Q11_hhid: replace L1logexpenses = L1logexpenses[2] if survey==3
by Q11_hhid: replace L1logsavings = L1logsavings[2] if survey==3 
by Q11_hhid: replace L1debt = L1debt[2] if survey==3
by Q11_hhid: replace L1risk = L1risk[2] if survey==3
by Q11_hhid: replace L1business = L1business[2] if survey==3
by Q11_hhid: replace L1riskaverse = L1riskaverse[2] if survey==3
by Q11_hhid: replace L1trust_people_index = L1trust_people_index[2] if survey==3
by Q11_hhid: replace L1trust_firms_index = L1trust_firms_index[2] if survey==3
by Q11_hhid: replace L1logpublic = L1logpublic[2] if survey==3
by Q11_hhid: replace L1logprivate = L1logprivate[2] if survey==3
by Q11_hhid: replace L1elec = L1elec[2] if survey==3
by Q11_hhid: replace L1size = L1size[2] if survey==3
by Q11_hhid: replace L1age = L1age[2] if survey==3
by Q11_hhid: replace L1educ = L1educ[2] if survey==3
by Q11_hhid: replace L1scheduled = L1scheduled[2] if survey==3
by Q11_hhid: replace L1backward = L1backward[2] if survey==3
by Q11_hhid: replace L1satisfaction = L1satisfaction[2] if survey==3
by Q11_hhid: replace L1expend = L1expend[2] if survey==3


eststo clear

* Full sample models
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt, vce(cluster unique_id)
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt L1risk L1business L1riskaverse, vce(cluster unique_id)
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt L1risk L1business L1riskaverse L1trust_people_index L1trust_firms_index, vce(cluster unique_id)
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt L1risk L1business L1riskaverse L1trust_people_index L1trust_firms_index L1logpublic L1logprivate L1elec L1size L1age L1educ L1scheduled L1backward L1satisfaction L1expend, vce(cluster unique_id)
* Subsample models
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt if installed==1, vce(cluster unique_id)
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt L1risk L1business L1riskaverse if installed==1, vce(cluster unique_id)
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt L1risk L1business L1riskaverse L1trust_people_index L1trust_firms_index if installed==1, vce(cluster unique_id)
eststo: xtlogit tvadopted L1logexpenses L1logsavings L1debt L1risk L1business L1riskaverse L1trust_people_index L1trust_firms_index L1logpublic L1logprivate L1elec L1size L1age L1educ L1scheduled L1backward L1satisfaction L1expend if installed==1, vce(cluster unique_id)

/*

* NB: Coefficients are odds-ratios, so the esttab command below needs to be run to exp transform coefficients

esttab using "./Adopt_panel.tex", replace b(%9.2f) booktabs stats(N N_clust, labels("Observations" "Habitations") fmt(0 0)) /// 
eqlabels(none) eform noconstant se label nonotes legend star(* 0.10 ** 0.05 *** 0.01) ///
mtitles("Model" "Model" "Model" "Model" "Model" "Model" "Model" "Model") ///
mgroups("Full sample" "Subsample: MGP service installed", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
addnote ("Dependent Variable: MGP adoption." "Standard errors in parentheses and clustered by habitation." "All explanatory variables are measured pre-treatment.") 
*/


*	************************************************************************
*								END OF DO FILE 
*	************************************************************************
